// Author: James Gray
// This program simulates a bank account ATM.

import java.util.*;

public class BankAccountSimulator {

	//main method prints the framework of the program and calls the various methods
	public static void main(String[] args) {
		
		Scanner stdin = new Scanner(System.in);	
		
		//declare variables
		double openBalance;
		double balance;
		double transactions;
		
		//Program title is printed and GUI prompts user for preliminary values
		System.out.println("\n\tB A N K   A C C O U N T   S I M U L A T I O N \n");
		System.out.print("\tInput the account's opening balance ==> ");
			balance = stdin.nextInt();
			openBalance = balance;
		System.out.print("\tInput the number of transactions ==> ");
			transactions = stdin.nextInt();
		System.out.println("\n\t\t\t\t\tOpening  Transaction  Closing");	
			for(int i=1; i<=transactions; i++) {
				balance = doTransaction(stdin, balance);	

			}

		//accrue interest
		System.out.print("\tInput the current interest rate ==> ");
			double rate = stdin.nextDouble();
			balance = applyInterest(balance, rate);

		//account summary printed based on the initial balance, final balance, and difference between the two	
		System.out.println("\n\tAccount Reporting:");
		System.out.println("\t\t\t Opening\t Closing\t Difference");	
		System.out.println(" \t\t\t " + openBalance + "\t\t " + balance + "\t" + (balance-openBalance) + "\n");	

	}

	//"doTransaction" method prompts user for transaction information	
	public static double doTransaction(Scanner in, double balance) {
		
		Scanner stdin = new Scanner(System.in);
		
		//declare variables
		double amount;
		
		System.out.println("\tInput:");
		System.out.print("\t   Type > ");
			String type = stdin.next();
		System.out.print("\t   Details > ");
			String details = stdin.next();
		System.out.print("\t   Amount > ");
			amount = stdin.nextDouble();
		System.out.print("\t\t\t" + type + ", " + details + "\t");
		balance = updateTheAccount(balance, amount);
		return balance;

	}

	//"updateTheAccount" computes the transaction and modifies the balance accordingly	
	public static double updateTheAccount(double balance, double amount) {
		System.out.println(balance + "\t " + amount + "\t       " + (balance+amount) + "\n");
		balance = balance+amount;
		return balance;

	}
	
	//"applyInterest" accrues interest on the final balance
	public static double applyInterest(double balance, double rate) {
		balance = ((balance * (rate / 100)) + balance);
		return balance;

	}

}

	
